package com.reader.cms;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import javax.servlet.MultipartConfigElement;

@SpringBootApplication
@MapperScan(basePackages = {"com.reader.cms.mapper.**"})
@ComponentScan(basePackages = {"com.reader.cms.**","com.reader.core.*"})
public class ReaderCmsApplication {


    @Value("${Upload.FileSize}")
    private String FileSize;

    @Value("${Upload.RequestSize}")
    private String RequestSize;

    public static void main(String[] args) {
        SpringApplication.run(ReaderCmsApplication.class, args);
    }


    /**
     * 可打印配置文件错误详细信息
     * @return
     */
  @Bean
    public static PropertySourcesPlaceholderConfigurer placeholderConfigurer() {
        PropertySourcesPlaceholderConfigurer c = new PropertySourcesPlaceholderConfigurer();
        c.setIgnoreUnresolvablePlaceholders(true);
        return c;
    }
    /**
     * 文件上传配置
     * @return
     */
    @Bean
    public MultipartConfigElement multipartConfigElement() {
        MultipartConfigFactory factory = new MultipartConfigFactory();
        //文件最大
        factory.setMaxFileSize(FileSize); //KB,MB
        /// 设置总上传数据总大小
        factory.setMaxRequestSize(RequestSize);
        return factory.createMultipartConfig();
    }

}
